package com.lsc.jiujia.util;

import com.alibaba.fastjson.JSONObject;
import com.sun.istack.internal.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.net.InetSocketAddress;
import java.net.Proxy;

@Slf4j
@Service
public class PlayUtil {

    private String url = "https://cloud.cn2030.com/sc/wx/HandlerSubscribe.ashx";

    @Autowired
    private RestTemplate restTemplate;


    //获取医院信息
    public String getHospital(){
        return null;
    }

    //预约

    //获取时间

    //获取验证码

    //
    public JSONObject sendRestfulReq(@NotNull String ip,@NotNull Integer port,@NotNull String uri, @NotNull HttpMethod method, @NotNull HttpEntity<?> entity, @NotNull Class<?> clazz, Object... uriVariables) {

        //设置请求IP
            SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
            simpleClientHttpRequestFactory.setProxy(new Proxy(Proxy.Type.HTTP,new InetSocketAddress(ip,port))); // 添加代理 ip 和 port 即可
            restTemplate.setRequestFactory(simpleClientHttpRequestFactory);


        ResponseEntity<?> exchange = restTemplate.exchange(uri, method, entity, clazz, uriVariables);
        if (exchange.getBody() == null) {
            log.error("sendRestfulReq->exchange:[{}]",exchange);
            return new JSONObject();
        }
        return JSONObject.parseObject(exchange.getBody().toString());
    }
}
